package com.ops.memcache.bean;


import com.ops.memcache.MemCache;
import com.ops.uitl.data.DataMap;
import com.ops.uitl.data.DatasetList;
import com.ops.uitl.data.IData;
import com.ops.uitl.data.IDataset;
import com.ops.uitl.tapestry.PageData;

public class MemCacheBean {
  public MemCacheBean() {
  }

  public IDataset query_MemcacheInfo_bean(PageData pd, IData data, String chan_id) throws Exception {
    MemCacheDao dao = new MemCacheDao(pd);
    new DatasetList();
    IDataset dataset = dao.query_MemcacheInfo_dao(data, pd, chan_id);
    pd.cleanupConnections();
    return dataset;
  }

  public IDataset MemCacheControl(PageData pd, IData param) throws Exception {
    DatasetList dataset = new DatasetList();
    String oper_type = param.getString("MODE", "1");
    if("1".equals(oper_type)) {
      return MemCache.memcache_Stats(pd, param);
    } else {
      DataMap data;
      if("2".equals(oper_type)) {
        data = new DataMap();
        if(!param.getString("KEY").equals((Object)null)) {
          data.put("VALUE", MemCache.memcache_Get(param.getString("KEY")));
          dataset.add(data);
        }

        return dataset;
      } else if("3".equals(oper_type)) {
        data = new DataMap();
        if(MemCache.updateCache(param.getString("KEY"), param.getString("VALUE")).booleanValue()) {
          data.put("X_RESULTINFO", param.getString("KEY") + " 更新成功！");
          dataset.add(data);
        } else {
          data.put("X_RESULTINFO", "更新失败！");
          data.put("X_RESULTCODE", "-1");
          dataset.add(data);
        }

        return dataset;
      } else if("reload".equals(oper_type)) {
        data = new DataMap();
        MemCache.memcache_reload();
        data.put("X_RESULTINFO", "MemCache reload 成功！");
        dataset.add(data);
        return dataset;
      } else {
        return dataset;
      }
    }
  }
}
